﻿
@model BBICMS.Model.ViewModel.Back.AddUserVM
@{

    ViewBag.Title = "添加帐号";
    ViewBag.PageTitle = ViewBag.Title + "_帐号安全";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
    var options = new AjaxOptions()
      {
          Url = Url.Action("AddUser", "Security"),
          LoadingElementId = "saving",
          LoadingElementDuration = 2000,
          //   Confirm = "Are you sure you want to save this User?"
          OnSuccess = "updateSuccess"

      };
}


@section leftNav{
    @Html.Partial("_NavForSecurity")
}


<div class="toolbar">
    <a href="#" class="showmenu"><i class="glyphicon glyphicon-th-list"></i></a>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index","Home")"><i class="glyphicon glyphicon-home"></i> 控制面板</a></li>
        <li><a href="@Url.Action("Index")">帐号安全</a></li>
        <li class="active">@ViewBag.Title</li>
    </ol>
</div>

<div class="main-content">

    <div class="panel panel-default">
        <div class="panel-heading">
            <i class="glyphicon glyphicon-file"></i> @ViewBag.Title
        </div>
        <div class="panel-body">
            @using (Ajax.BeginForm("AddUser", null, options, new { @class = "form-horizontal", role = "form" }))
            {

                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)

                <div class="form-group">
                    @Html.LabelFor(model => model.UserName, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.UserName, ViewData).Watermark })
                        @Html.ValidationMessageFor(model => model.UserName)

                    </div>

                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Password, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.PasswordFor(model => model.Password, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Password, ViewData).Watermark })
                        @Html.ValidationMessageFor(model => model.Password)
                    </div>

                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.ConfirmPassword, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.PasswordFor(model => model.ConfirmPassword, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ConfirmPassword, ViewData).Watermark })
                        @Html.ValidationMessageFor(model => model.ConfirmPassword)
                    </div>

                </div>



                <div class="form-group">
                    <div class="col-sm-offset-2 col-md-10">
                        <input type="submit" class="btn btn-primary" value="添加帐号" />
                    </div>
                </div>

            }
        </div>
    </div>



</div>


@section Footer {
    @Scripts.Render("~/bundles/jqueryval")


    <script>
     

    function updateSuccess(data) {

        //  console.log(data.Oicq);
        toastr.options = {
            "positionClass": "toast-bottom-full-width"
        }
        if (data) {
            toastr.success('帐号已添加成功！', '@ViewBag.Title');
            setTimeout(function () {
                location.href = 'index';
            }, 2000);
        } else {
            toastr.error('帐号添加失败！', '@ViewBag.Title')
        }


    }



    $(function () {
       
        //当前菜单
        $('.mainmenu>li:nth(4)').addClass('nav-open').find('.submenu>li:nth(0)>a').addClass('active');

        //转换boostrap 验证
        $('span.field-validation-valid, span.field-validation-error').each(function () {
              $(this).addClass('help-block');
        });

             var $form = $('form');
             var $validate = $form.validate();
             var errorClass = "has-error";
             //var successClass = "has-success";
             $validate.settings.errorClass = errorClass;
             var previousEPMethod = $validate.settings.errorPlacement;
             $validate.settings.errorPlacement = $.proxy(function (error, inputElement) {
                     if (previousEPMethod) {
                             previousEPMethod(error, inputElement);
                         }
                     inputElement.parent().addClass(errorClass)
                 }, $form[0]);

             var previousSuccessMethod = $validate.settings.success;
             $validate.settings.success = $.proxy(function (error) {
                     //we first need to remove the class, cause the unobtrusive success method removes the node altogether
                 error.parent().parent().removeClass(errorClass)
                     if (previousSuccessMethod) {
                             previousSuccessMethod(error);
                         }
                 });


        });
    </script>
}
